package com.vv.config;

import org.springframework.web.WebApplicationInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.Set;

public class MySpringServletContainerInitializer implements ServletContainerInitializer {

    public void onStartup(Set<Class<?>> webAppInitializerClasses, ServletContext servletContext) throws ServletException {
        //判断传过来的class集合是否为空
        if(webAppInitializerClasses != null){
            // 不为空，循环创建WebApplicationInitializer 对象，并调用onStartup方法
            for(Class<?> clazz : webAppInitializerClasses){
                try{
                    WebApplicationInitializer webApplicationInitializer = (WebApplicationInitializer)clazz.newInstance();
                    webApplicationInitializer.onStartup(servletContext);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}
